#include "cont.h"


void Container::addFigure(Shape * newFigure)
{
    shapes.push_back(newFigure);
}
void Container::deleteFigure(int i)
{
    shapes.erase(shapes.begin() + i);
}
void Container::moveToNewXY(int newX, int newY, int i)
{
    shapes.at(i)->offsetToNewXY(newX, newY);
}
void Container::setProperties(int i)
{
    shapes.at(i)->setProperties();

}
void Container::saveFile()
{
    ofstream file("output.txt");
    if (file.is_open())
    {
        for (int i = 0; i < shapes.size(); i++)
        {
            vector<int> tmp = shapes.at(i)->getProperties();
            file << shapes.at(i)->Type()[0]<<endl;
            for (int j = 0; j < tmp.size(); j++)
            {

                file << tmp.at(j) << endl;
            }
        }
        cout<<"file successfully saved";
    }

    file.close();
}
void Container::loadFile()
{
    ifstream file("output.txt");
    if (file.is_open())
    {
        while (true) {
            if (file.eof()) { break; }
            else{

            char tmp;
            file >> tmp;
            if (!file.good())
                break;
            Shape *figure;
            vector<int> properties;
            switch (tmp)
            {
            case 'R':{
                for(int i=0;i<4;i++)
                {
                    int a;
                    file >>a;
                    properties.push_back(a);
                }

                figure = new Rhombus(properties);
                break; }
            case 'T':{
                for(int i=0;i<4;i++)
                {
                    int a;
                    file >>a;
                    properties.push_back(a);
                }
                figure = new Triangle(properties);
                break; }
            case 'C':{
                for(int i=0;i<3;i++)
                {
                    int a;
                    file >>a;
                    properties.push_back(a);
                }
                figure = new Circle(properties);
                break; }
            }

            shapes.push_back(figure);}
        }
         cout<<"file successfully load";
    }
    file.close();
}
void Container::printShapes()
{
    for (int i = 0; i < shapes.size(); i++)
        shapes.at(i)->printProperties();
}

